package dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import form.ConnectionDB;

import model.Muctintuc;

public class MuctintucDAO {

	public static ArrayList<Muctintuc> select() throws ClassNotFoundException, SQLException {
		Connection connection = ConnectionDB.getConnection();
		ArrayList<Muctintuc> listMuctintuc = new ArrayList<>();
		String sql = "select * from muctintuc";
		PreparedStatement ps = connection.prepareStatement(sql);
		ResultSet resultSet = ps.executeQuery();
		while(resultSet.next()){
			int muctintucid = resultSet.getInt(1);
			String tenmuctintuc = resultSet.getString(2);
			listMuctintuc.add(new Muctintuc(muctintucid, tenmuctintuc));
			
			
		}
		connection.close();
		
		
		return listMuctintuc;
		
	}
	public static void main(String[] args) throws ClassNotFoundException, SQLException {
//		ArrayList<Muctintuc> listMuctintuc = select();
//		for (Muctintuc muctintuc : listMuctintuc) {
//			System.out.println(muctintuc.toString());
//		}
	}
}
